<?php

namespace App\Extensions\Actions\Upload;

use App\Extensions\Actions\RowAction;
use App\Models\AdminUser;
use App\PatentApply;
use Carbon\Carbon;
use Encore\Admin\Actions\Response;
use Illuminate\Http\Request;

class PatentApplyFileUploadAction extends RowAction
{
    public $name = '交底书';

    public function handle(PatentApply $model, Request $request): Response
    {
        //交底书
        $model->storeFile($request->file('file'), 'file', null, [
            'file_time' => Carbon::now()
        ]);
        return $this->response()->success('操作成功')->refresh();
    }

    public function form()
    {
        $this->file('file', '交底书')->required();
    }

    public function authorize(AdminUser $user, $model): bool
    {
        return $model->user_id == $user['id'] || $user->role_type == 1 || $user->id == 1;
    }
}
